<template>
	<view>
		<view style="position: relative;" @click="ad_click">
		    <u-image :src="ad_data.img" width="100%" :height="pheight+'px'" mode="scaleToFill">
		    	<view slot="loading" style="font-size: 24px;">加载中...</view>
		    </u-image>
			<view style="position: absolute;right: 10px;padding: 3px 8px;background-color: #000;border-radius: 3px;display: flex;color: #fff;" :style="{'top':statusHeight+10+'px'}">
				<u-count-down :time="ad_data.time * 1000" format="ss" @finish="go_app"></u-count-down>
				<view style="font-size: 14px;line-height: 22px;margin-left: 2px;">秒后关闭</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ad_data: {}, //广告数据
				pheight: 0, //屏幕高度
				statusHeight: 0
			}
		},
		onLoad() {
			this.pheight = uni.getSystemInfoSync().screenHeight
			this.statusHeight = uni.getSystemInfoSync().statusBarHeight
			console.log(this.pheight)
			this.getAd()
		},
		methods: {
			// 弹窗广告点击
			ad_click(){
				if(this.ad_data.url!==''){
					plus.runtime.openURL(this.ad_data.url)
				}
			},
			// 获取广告
			getAd(){
				uni.request({
					url: getApp().globalData.websiteUrl + "/index.php/appv1/kxapps/kp",
					success: (res) => {
						console.log(res.data)
						this.ad_data = res.data
					},
					fail(a) {
						console.log(a)
					}
				})
			},
			// 进入首页
			go_app(){
				uni.switchTab({
					url:'/pages/index/index'
				})
			}
		}
	}
</script>

<style>

</style>
